import App from './App'
import pageJump from './tools/pageJump' // 页面跳转封装
import check from './tools/check' // js校验封装
import uploadImg from './tools/uploadImgOss' // oss图片上传封装
import http from './tools/http' // 网络请求模块
import jsMd5 from 'js-md5' // 引入md5加密 
import store from './store/index' // store状态数据
import uviewPlus from 'uview-plus' // 引入uview-plus
import '@/static/css/common.css' // 引入公共css
import '@/static/css/animate.min.css' // 引入公共css
 
import { createSSRApp } from 'vue'

export function createApp() {
	const app = createSSRApp(App)
	uni.getSystemInfo({
		success: function(e) {
			app.config.globalProperties.statusBar = e.statusBarHeight // 状态栏高度
			// #ifndef MP
			if (e.platform === 'android') {
				app.config.globalProperties.customBar = e.statusBarHeight + 50
			} else {
				app.config.globalProperties.customBar = e.statusBarHeight + 45
			}
			// #endif

			// #ifdef MP-WEIXIN 
			let customWEIXIN = uni.getMenuButtonBoundingClientRect() // 微信导航栏的信息
			app.config.globalProperties.customBar = customWEIXIN.bottom + customWEIXIN.top - e
				.statusBarHeight
			// #endif
		}
	})
	app.config.globalProperties.$pageJump = pageJump // 页面跳转封装
	app.config.globalProperties.$check = check // js校验封装
	app.config.globalProperties.$uploadImg = uploadImg // oss图片上传封装
	app.config.globalProperties.$http = http // 网络请求模块
	app.config.globalProperties.$md5 = jsMd5 // 引入md5加密
	app.config.globalProperties.$store = store // store状态数据
	// 全局封装的showToast提示框
	app.config.globalProperties.$showToast = function(msg, type) {
		if (!msg) {
			return
		}
		uni.showToast({
			title: msg,
			icon: type,
			duration: 2000
		})
	}
	// 全局封装的showModal模态框
	app.config.globalProperties.$showModal = function(msg) {
		if (!msg) {
			return
		}
		uni.showModal({
			title: '温馨提示',
			content: msg,
			confirmColor: '#3178FF',
			showCancel: false,
			success: function(res) {
				if (res.confirm) {
					// console.log('用户点击确定')
				}
			},
		})
	}
	app.use(uviewPlus).use(store)
	return { app }
}
